using UnityEngine;

namespace CGF
{
    /// <summary>
    /// 框架配置
    /// </summary>
    public static class Define
    {
        public const string BundleFolder = "CGFramework/Bundles";
        public const string ConfigFolder = "CGFramework/Bundles/Configs";
        public const string ShaderFolder = "CGFramework/Bundles/Shaders";
        public const string ScriptsHotfixFolder = "CGFramework/Scripts_Hotfix";
        public const string GenerateDir = "CGFramework/Scripts_Hotfix/AutoGenerate";
        public const string DevelopScriptDir = "CGFramework/Scripts_Hotfix/Develop";
        public const string DllAssetName = "Assembly-CSharp";
        public const string HashFileName = "hash.txt";
        public const string MetadataAbName = "metadata";
        public const string I18NAbName = "i18n";
        public const string AutoUpdateAbName = "auto_update";
        public const string StreamingPathAbFolder = "AssetBundles";
        public static readonly string AbCachePath = Application.persistentDataPath + "/AssetBundles";
        public static string AbExtName
        {
            get
            {
                //WebGL需要服务端指定特殊的MIME浏览器才能自动解压，所以需要一个特殊的后缀，以便配置MIME(application/octet-stream)
                //App是使用插件解压，为了避免服务端配置MIME，使用常见的文件格式最省事
                return IsWebGL ? ".ab" : ".zip";
            }
        }

        public static string StreamPathUrl
        {
            get
            {
                string path = "file://" + Application.dataPath + "/StreamingAssets";
                switch (Application.platform)
                {
                    case RuntimePlatform.Android:
                        path = "jar:file://" + Application.dataPath + "!/assets";
                        break;
                    case RuntimePlatform.IPhonePlayer:
                        path = "file:///" + Application.dataPath + "/Raw";
                        break;
                }
                return path;
            }
        }

        public static bool IsWebGL
        {
            get
            {
#if UNITY_EDITOR
                return UnityEditor.EditorUserBuildSettings.activeBuildTarget == UnityEditor.BuildTarget.WebGL;
#else
                return Application.platform == RuntimePlatform.WebGLPlayer;
#endif
            }
        }

    }
}
